package www.openteam.com.model.business;


import www.openteam.com.OTApplication;
import www.openteam.com.base.BaseModel;
import www.openteam.com.bean.InsertStatus;
import www.openteam.com.exception.ApiException;
import www.openteam.com.subscribe.CommonSubscriber;
import www.openteam.com.transformer.CommonTransformer;

/**
 * Created by kylin on 2016/10/20.
 */

public class InsertCustomInfoModel extends BaseModel {
    boolean isInsert = false;

    public boolean insertCustomInfo(String code, String name,
                                    String type, String paytime,
                                    String moneytype, String SendAddress,
                                    String connecter, String BusinessMan,
                                    String CreditNumb, String cTel, final InsertCustomInfoOnListener insertCustomInfoOnListener) {

        httpApiService.insertCustomInfo(code, name, type, paytime, moneytype, SendAddress, connecter, BusinessMan, CreditNumb, cTel
        ).compose(new CommonTransformer<InsertStatus>())
                .subscribe(new CommonSubscriber<InsertStatus>(OTApplication.getmContext()) {
                    @Override
                    public void onNext(InsertStatus insertStatus) {
                        isInsert = true;
                        insertCustomInfoOnListener.insertCISuccess(insertStatus);
                    }

                    @Override
                    protected void onError(ApiException e) {
                        super.onError(e);
                        isInsert = false;
                        insertCustomInfoOnListener.insertCIFail(e);
                    }
                });
        return isInsert;
    }


    public interface InsertCustomInfoOnListener {
        void insertCISuccess(InsertStatus insertStatus);

        void insertCIFail(Throwable throwable);


    }
}
